<?php

namespace paper\helper;

class Time
{
    /**
     * 获取传入时间戳表示的时间当天0点的时间戳
     * @param int $time
     * @return bool|int
     */
    public static function thatDayTime(int $time): bool|int
    {
        return strtotime(date("Y-m-d  00:00:00", $time));
    }

    /**
     * 获取给定时间戳所在月份 的第一天0点和最后一天24点的时间戳
     * @param int $time
     * @return array
     */
    public static function month(?int $time = null): array
    {
        $firstDay = strtotime(date("Y-m-01 00:00:00", $time ?: time()));
        $lastDay = date('Y-m-d', strtotime("$firstDay +1 month -1 day"));
        return [$firstDay, $lastDay];
    }

    /**
     * 获取给定时间戳所在日0点和24点的时间戳
     * @param int $time
     * @return array
     */
    public static function day(int $time): array
    {
        $first = strtotime(date("Y-m-d 00:00:00", $time));
        $last = $first + 24 * 60 * 60;
        return [$first, $last];
    }

    public static function week(): array
    {
        $nextMonday = strtotime('next Monday');
        $thisMonday = $nextMonday - 60*60*24*7;
        return [$thisMonday, $nextMonday];
    }

    /**
     * 获取给定时间戳所在年份的第一天0点和最后一天24点的时间戳
     * @param int $time
     * @return array
     */
    public static function year(int $time): array
    {
        $first = strtotime(date("Y-1-1 00:00:00", $time));
        $last = strtotime(date("Y-12-31 00:00:00", $time)) + 24 * 60 * 60;
        return [$first, $last];
    }
}